package org.jawa.core.database;

import javax.sql.DataSource;

public class JawaDataSourceFactory {
	private static DataSource dataSource;

	public JawaDataSourceFactory() {
		dataSource = null;
	}

	public void init() {
		if (null == dataSource) {
			dataSource = new JawaDataSource();
		}
	}

	public DataSource getDataSource() {
		if (null == dataSource) {
			dataSource = new JawaDataSource();
		}
		return dataSource;
	}

	public void destroy() throws Exception {
		if (DbConnectionManager.getConnectionProvider() != null){
			DbConnectionManager.destroyConnectionProvider();
		}
		dataSource = null;
	}

	public void restart() {
		try {
			destroy();
			init();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
